package com.cm.controller;

import com.cm.pojo.*;
import com.cm.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:  EmpController
 * Package: com.cm.controller
 * Description:
 *
 * @Author:
 * @Create: 2025/8/10  4:08
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/emps")
public class EmpController {
  @Autowired
    private EmpService empService;

  /*
  使用参数来接收
  * */
 /*   @GetMapping
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                        String name, Integer gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        PageResult<Emp> pageresult=empService.list(page,pageSize,name,gender,begin,end);
        return Result.success(pageresult);
    }*/




// 使用对象来接收参数进行条件查询
    @GetMapping
    public Result list(EmpQueryParam param){
        PageResult<Emp> pageresult=empService.list(param);
        return Result.success(pageresult);
    }
 
 @PostMapping
 public Result save(@RequestBody Emp emp){
        empService.save(emp);
        return Result.success();
 }

 @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        empService.delete(ids);
        log.info("删除的id是:{}",ids);
        return Result.success();
 }
 @GetMapping("/{id}")
    public Result getInfor(@PathVariable Integer id){
        Emp emp=empService.getInfor(id);
        return Result.success(emp);
 }
}
